test: add unit tests for static helpers in fabrics.c#3277
Merged
igaw merged 1 commit intolinux-nvme:masterfrom Apr 16, 2026
Merged
test: add unit tests for static helpers in fabrics.c#3277igaw merged 1 commit intolinux-nvme:masterfrom
igaw merged 1 commit intolinux-nvme:masterfrom
Conversation
98688cd to
c492a6e
Compare
Adds libnvme/test/test-fabrics.c, which tests the static helper functions in src/nvme/fabrics.c without modifying any production source. The technique is to define 'static' to nothing and then #include the source file directly. This exposes all translation-unit-local symbols in the test binary. No #ifdef UNIT_TEST guards or visibility changes are needed — the production files are left completely untouched. Functions covered: strchomp, hostid_from_hostnqn, __add_bool_argument, __add_hex_argument, __add_int_argument, __add_int_or_minus_one_argument, __add_argument, inet4_pton, inet_pton_with_scope, traddr_is_hostname, unescape_uri The test is gated on want_fabrics in meson.build, matching the conditional that guards the uriparser test above it. Signed-off-by: Martin Belanger <[email protected]>
c492a6e to
0e18179
Compare
Collaborator
|
Thanks. Let's see how this goes in the long run. I do think having proper unit tests also for such functions is not a bad thing. Though it has the change to get out of hand. But that's tomorrow's problem. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@igaw - I thought it would be a good idea to add unit tests for the
staticfunctions infabrics.cincludingtraddr_is_hostname().Adds
libnvme/test/test-fabrics.c, which tests the static helper functions insrc/nvme/fabrics.cwithout modifying any production source.The technique is to define
staticto nothing and then#includethe source file directly. This exposes all translation-unit-local symbols in the test binary. No#ifdef UNIT_TESTguards or visibility changes are needed — the production files are left completely untouched.Functions covered:
strchomp, hostid_from_hostnqn, __add_bool_argument, __add_hex_argument, _add_int_argument, __add_int_or_minus_one_argument, __add_argument, inet4_pton, inet_pton_with_scope, traddr_is_hostname, unescape_uriThe test is gated on
want_fabricsinmeson.build, matching the conditional that guards the uriparser test above it.The
traddr_is_hostnametests include the key regression case: scoped IPv6 addresses (e.g."fe80::1%lo") must not be mis-classified as hostnames. A plaininet_pton()call would fail on the%delimiter and wrongly return true;inet_pton_with_scope()handles it correctly.